home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / byacc 1.8.2 / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-04  |  8.1 KB  |  446 lines  |  [TEXT/R*ch]

  1. /* routines for printing error messages     */
  2.  
  3. #include "defs.h"
  4.  
  5.  
  6. #if __STDC__
  7. void fatal(char *msg)
  8. #else
  9. void fatal(msg)
  10. char *msg;
  11. #endif
  12. {
  13.     fprintf(stderr, "%s: f - %s\n", myname, msg);
  14.     done(2);
  15. }
  16.  
  17.  
  18. #if __STDC__
  19. void no_space(void)
  20. #else
  21. void no_space()
  22. #endif
  23. {
  24.     fprintf(stderr, "%s: f - out of space\n", myname);
  25.     done(2);
  26. }
  27.  
  28.  
  29. #if __STDC__
  30. void open_error(char *filename)
  31. #else
  32. void open_error(filename)
  33. char *filename;
  34. #endif
  35. {
  36.     fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
  37.     done(2);
  38. }
  39.  
  40.  
  41. #if __STDC__
  42. void unexpected_EOF(void)
  43. #else
  44. void unexpected_EOF()
  45. #endif
  46. {
  47.     fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
  48.         myname, lineno, input_file_name);
  49.     done(1);
  50. }
  51.  
  52.  
  53. #if __STDC__
  54. void print_pos(char *st_line, char *st_cptr)
  55. #else
  56. void print_pos(st_line, st_cptr)
  57. char *st_line;
  58. char *st_cptr;
  59. #endif
  60. {
  61.     register char *s;
  62.  
  63.     if (st_line == 0) return;
  64.     for (s = st_line; *s != '\n'; ++s)
  65.     {
  66.     if (isprint(*s) || *s == '\t')
  67.         putc(*s, stderr);
  68.     else
  69.         putc('?', stderr);
  70.     }
  71.     putc('\n', stderr);
  72.     for (s = st_line; s < st_cptr; ++s)
  73.     {
  74.     if (*s == '\t')
  75.         putc('\t', stderr);
  76.     else
  77.         putc(' ', stderr);
  78.     }
  79.     putc('^', stderr);
  80.     putc('\n', stderr);
  81. }
  82.  
  83.  
  84. #if __STDC__
  85. void syntax_error(int st_lineno, char *st_line, char *st_cptr)
  86. #else
  87. void syntax_error(st_lineno, st_line, st_cptr)
  88. int st_lineno;
  89. char *st_line;
  90. char *st_cptr;
  91. #endif
  92. {
  93.     fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
  94.         myname, st_lineno, input_file_name);
  95.     print_pos(st_line, st_cptr);
  96.     done(1);
  97. }
  98.  
  99.  
  100. #if __STDC__
  101. void unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
  102. #else
  103. void unterminated_comment(c_lineno, c_line, c_cptr)
  104. int c_lineno;
  105. char *c_line;
  106. char *c_cptr;
  107. #endif
  108. {
  109.     fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
  110.         myname, c_lineno, input_file_name);
  111.     print_pos(c_line, c_cptr);
  112.     done(1);
  113. }
  114.  
  115.  
  116. #if __STDC__
  117. void unterminated_string(int s_lineno, char *s_line, char *s_cptr)
  118. #else
  119. void unterminated_string(s_lineno, s_line, s_cptr)
  120. int s_lineno;
  121. char *s_line;
  122. char *s_cptr;
  123. #endif
  124. {
  125.     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
  126.         myname, s_lineno, input_file_name);
  127.     print_pos(s_line, s_cptr);
  128.     done(1);
  129. }
  130.  
  131.  
  132. #if __STDC__
  133. void unterminated_text(int t_lineno, char *t_line, char *t_cptr)
  134. #else
  135. void unterminated_text(t_lineno, t_line, t_cptr)
  136. int t_lineno;
  137. char *t_line;
  138. char *t_cptr;
  139. #endif
  140. {
  141.     fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
  142.         myname, t_lineno, input_file_name);
  143.     print_pos(t_line, t_cptr);
  144.     done(1);
  145. }
  146.  
  147.  
  148. #if __STDC__
  149. void unterminated_union(int u_lineno, char *u_line, char *u_cptr)
  150. #else
  151. void unterminated_union(u_lineno, u_line, u_cptr)
  152. int u_lineno;
  153. char *u_line;
  154. char *u_cptr;
  155. #endif
  156. {
  157.     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
  158. declaration\n", myname, u_lineno, input_file_name);
  159.     print_pos(u_line, u_cptr);
  160.     done(1);
  161. }
  162.  
  163.  
  164. #if __STDC__
  165. void over_unionized(char *u_cptr)
  166. #else
  167. void over_unionized(u_cptr)
  168. char *u_cptr;
  169. #endif
  170. {
  171.     fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
  172. declarations\n", myname, lineno, input_file_name);
  173.     print_pos(line, u_cptr);
  174.     done(1);
  175. }
  176.  
  177.  
  178. #if __STDC__
  179. void illegal_tag(int t_lineno, char *t_line, char *t_cptr)
  180. #else
  181. void illegal_tag(t_lineno, t_line, t_cptr)
  182. int t_lineno;
  183. char *t_line;
  184. char *t_cptr;
  185. #endif
  186. {
  187.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
  188.         myname, t_lineno, input_file_name);
  189.     print_pos(t_line, t_cptr);
  190.     done(1);
  191. }
  192.  
  193.  
  194. #if __STDC__
  195. void illegal_character(char *c_cptr)
  196. #else
  197. void illegal_character(c_cptr)
  198. char *c_cptr;
  199. #endif
  200. {
  201.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
  202.         myname, lineno, input_file_name);
  203.     print_pos(line, c_cptr);
  204.     done(1);
  205. }
  206.  
  207.  
  208. #if __STDC__
  209. void used_reserved(char *s)
  210. #else
  211. void used_reserved(s)
  212. char *s;
  213. #endif
  214. {
  215.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
  216. %s\n", myname, lineno, input_file_name, s);
  217.     done(1);
  218. }
  219.  
  220.  
  221. #if __STDC__
  222. void tokenized_start(char *s)
  223. #else
  224. void tokenized_start(s)
  225. char *s;
  226. #endif
  227. {
  228.      fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
  229. declared to be a token\n", myname, lineno, input_file_name, s);
  230.      done(1);
  231. }
  232.  
  233.  
  234. #if __STDC__
  235. void retyped_warning(char *s)
  236. #else
  237. void retyped_warning(s)
  238. char *s;
  239. #endif
  240. {
  241.     fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
  242. redeclared\n", myname, lineno, input_file_name, s);
  243. }
  244.  
  245.  
  246. #if __STDC__
  247. void reprec_warning(char *s)
  248. #else
  249. void reprec_warning(s)
  250. char *s;
  251. #endif
  252. {
  253.     fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
  254. redeclared\n", myname, lineno, input_file_name, s);
  255. }
  256.  
  257.  
  258. #if __STDC__
  259. void revalued_warning(char *s)
  260. #else
  261. void revalued_warning(s)
  262. char *s;
  263. #endif
  264. {
  265.     fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
  266. redeclared\n", myname, lineno, input_file_name, s);
  267. }
  268.  
  269.  
  270. #if __STDC__
  271. void terminal_start(char *s)
  272. #else
  273. void terminal_start(s)
  274. char *s;
  275. #endif
  276. {
  277.     fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
  278. token\n", myname, lineno, input_file_name, s);
  279.     done(1);
  280. }
  281.  
  282.  
  283. #if __STDC__
  284. void restarted_warning(void)
  285. #else
  286. void restarted_warning()
  287. #endif
  288. {
  289.     fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
  290. redeclared\n", myname, lineno, input_file_name);
  291. }
  292.  
  293.  
  294. #if __STDC__
  295. void no_grammar(void)
  296. #else
  297. void no_grammar()
  298. #endif
  299. {
  300.     fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
  301. specified\n", myname, lineno, input_file_name);
  302.     done(1);
  303. }
  304.  
  305.  
  306. #if __STDC__
  307. void terminal_lhs(int s_lineno)
  308. #else
  309. void terminal_lhs(s_lineno)
  310. int s_lineno;
  311. #endif
  312. {
  313.     fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
  314. of a production\n", myname, s_lineno, input_file_name);
  315.     done(1);
  316. }
  317.  
  318.  
  319. #if __STDC__
  320. void prec_redeclared(void)
  321. #else
  322. void prec_redeclared()
  323. #endif
  324. {
  325.     fprintf(stderr, "%s: w - line %d of  \"%s\", conflicting %%prec \
  326. specifiers\n", myname, lineno, input_file_name);
  327. }
  328.  
  329.  
  330. #if __STDC__
  331. void unterminated_action(int a_lineno, char *a_line, char *a_cptr)
  332. #else
  333. void unterminated_action(a_lineno, a_line, a_cptr)
  334. int a_lineno;
  335. char *a_line;
  336. char *a_cptr;
  337. #endif
  338. {
  339.     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
  340.         myname, a_lineno, input_file_name);
  341.     print_pos(a_line, a_cptr);
  342.     done(1);
  343. }
  344.  
  345.  
  346. #if __STDC__
  347. void dollar_warning(int a_lineno, int i)
  348. #else
  349. void dollar_warning(a_lineno, i)
  350. int a_lineno;
  351. int i;
  352. #endif
  353. {
  354.     fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
  355. end of the current rule\n", myname, a_lineno, input_file_name, i);
  356. }
  357.  
  358.  
  359. #if __STDC__
  360. void dollar_error(int a_lineno, char *a_line, char *a_cptr)
  361. #else
  362. void dollar_error(a_lineno, a_line, a_cptr)
  363. int a_lineno;
  364. char *a_line;
  365. char *a_cptr;
  366. #endif
  367. {
  368.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
  369.         myname, a_lineno, input_file_name);
  370.     print_pos(a_line, a_cptr);
  371.     done(1);
  372. }
  373.  
  374.  
  375. #if __STDC__
  376. void untyped_lhs(void)
  377. #else
  378. void untyped_lhs()
  379. #endif
  380. {
  381.     fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
  382.         myname, lineno, input_file_name);
  383.     done(1);
  384. }
  385.  
  386.  
  387. #if __STDC__
  388. void untyped_rhs(int i, char *s)
  389. #else
  390. void untyped_rhs(i, s)
  391. int i;
  392. char *s;
  393. #endif
  394. {
  395.     fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
  396.         myname, lineno, input_file_name, i, s);
  397.     done(1);
  398. }
  399.  
  400.  
  401. #if __STDC__
  402. void unknown_rhs(int i)
  403. #else
  404. void unknown_rhs(i)
  405. int i;
  406. #endif
  407. {
  408.     fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
  409.         myname, lineno, input_file_name, i);
  410.     done(1);
  411. }
  412.  
  413.  
  414. #if __STDC__
  415. void default_action_warning(void)
  416. #else
  417. void default_action_warning()
  418. #endif
  419. {
  420.     fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
  421. undefined value to $$\n", myname, lineno, input_file_name);
  422. }
  423.  
  424.  
  425. #if __STDC__
  426. void undefined_goal(char *s)
  427. #else
  428. void undefined_goal(s)
  429. char *s;
  430. #endif
  431. {
  432.     fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
  433.     done(1);
  434. }
  435.  
  436.  
  437. #if __STDC__
  438. void undefined_symbol_warning(char *s)
  439. #else
  440. void undefined_symbol_warning(s)
  441. char *s;
  442. #endif
  443. {
  444.     fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
  445. }
  446.